﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Web.Question;
using PowerCreator.LMS.Question.Entiry;
using PowerCreator.LMS.Web.Course;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Common.Utils;

public partial class sysadmin_QuestionManager_AddQuestioninfo_mingci : PowerCreator.LMS.Web.Base.BasePage
{
    //ManagerCourseInfo courseInfoManager = new ManagerCourseInfo();
    //ManagerQuestionTypeInfo questionTypeManager = new ManagerQuestionTypeInfo();

    //ManagerQuestionInfo questionInfoManager = new ManagerQuestionInfo();
    ManagerQuestion objQuestion = new ManagerQuestion();
    Course objCourse = new Course();
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!GetRole(Role.AddQuestion))
        //{
        //    Script.ShowAndHistory("您没有添加试题的权限!", -1);
        //    return;
        //}
        if (!IsPostBack)
        {
            ViewState["TypeID"] = 5;
            ViewState["UserID"] = 10000;
            BinderDLL();
            InitPage();
        }
    }
    protected override void InitPage()
    {
        lab_AddQuestionInfo_danx_QuestionType.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_QuestionType", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_AddQuestionInfo_danx_AttributeTitle.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_AttributeTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_AddQuestionInfo_danx_CourseName.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_CourseName", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_AddQuestionInfo_danx_QuestionState.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_QuestionState", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_AddQuestionInfo_danx_QuestionQuestionDiffculty.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_QuestionDiffculty", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_AddQuestionInfo_danx_QuestionKen.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_Ken", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_AddQuestionInfo_danx_DefaultScore.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_DefaultScore", PowerCreator.LMS.Language.LanagetItemType.Page);

        lab_AddQuestionInfo_danx_ContentTitle.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_ContentTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_AddQuestionInfo_danx_QuestionContent.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_QuestionContent", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_AddQuestionInfo_danx_QuestionOption.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_QuestionOption", PowerCreator.LMS.Language.LanagetItemType.Page);


        btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnBack.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }

    private void BinderDLL()
    {
        rdbtn_QuestionType.DataSource = objQuestion.QueryQuestionType("");
        rdbtn_QuestionType.DataTextField = "QuestionTypeName";
        rdbtn_QuestionType.DataValueField = "QuestionTypeID";

        rdbtn_QuestionType.DataBind();
        rdbtn_QuestionType.Items[4].Selected = true;
        rdbtn_QuestionType.Items[0].Text = GetLanageValueByKey("lab_EditUserPaper_Question_Panduanti", PowerCreator.LMS.Language.LanagetItemType.Page);
        rdbtn_QuestionType.Items[1].Text = GetLanageValueByKey("lab_EditUserPaper_Question_Danxuanti", PowerCreator.LMS.Language.LanagetItemType.Page);
        rdbtn_QuestionType.Items[2].Text = GetLanageValueByKey("lab_EditUserPaper_Question_Duoxuanti", PowerCreator.LMS.Language.LanagetItemType.Page);
        rdbtn_QuestionType.Items[3].Text = GetLanageValueByKey("lab_EditUserPaper_Question_Tiankongti", PowerCreator.LMS.Language.LanagetItemType.Page);
        rdbtn_QuestionType.Items[4].Text = GetLanageValueByKey("lab_EditUserPaper_Question_Mingcijieshiti", PowerCreator.LMS.Language.LanagetItemType.Page);
        rdbtn_QuestionType.Items[5].Text = GetLanageValueByKey("lab_EditUserPaper_Question_Jiandati", PowerCreator.LMS.Language.LanagetItemType.Page);
        rdbtn_QuestionType.Items[6].Text = GetLanageValueByKey("lab_EditUserPaper_Question_Zuheti", PowerCreator.LMS.Language.LanagetItemType.Page);

        ddlCourseList.DataSource = objCourse.Query("");
        ddlCourseList.DataTextField = "CourseName";
        ddlCourseList.DataValueField = "Course_Id";
        ddlCourseList.DataBind();
        ddlCourseList.Items[0].Text = GetLanageValueByKey("Msg_ManagerQuestion_PleaseCheck", PowerCreator.LMS.Language.LanagetItemType.Page);

        ddlQuestionState.Items[1].Text = GetLanageValueByKey("dpdlst_ManagerQuestion_IsUse", PowerCreator.LMS.Language.LanagetItemType.Page);
        ddlQuestionState.Items[0].Text = GetLanageValueByKey("dpdlst_ManagerQuestion_UnUse", PowerCreator.LMS.Language.LanagetItemType.Page);

    }
    private bool PageCheck()
    {
        if (string.IsNullOrEmpty(txtDefaultScore.Text.Trim()) | string.IsNullOrEmpty(txtKen.Text.Trim()) | string.IsNullOrEmpty(txtQuestionContent.Value.Trim()))
        {
            Script.Alert(this, "msg", GetLanageValueByKey("msg_AddQuestionInfo_checkmsg1", PowerCreator.LMS.Language.LanagetItemType.Page));
            return false;
        }
        if (!PageValidate.IsNumber(txtDefaultScore.Text.Trim()))
        {
            Script.Alert(this, "msg", GetLanageValueByKey("Msg_QuestionToIn_checkmsg2", PowerCreator.LMS.Language.LanagetItemType.Page));
            return false;
        }
        if (ddlCourseList.SelectedValue == "-1")
        {
            Script.Alert(this, "msg", GetLanageValueByKey("Msg_QuestionToIn_checkmsg3", PowerCreator.LMS.Language.LanagetItemType.Page));
            return false;
        }
        return true;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!PageCheck())
        {
            return;
        }
        VOQuestion voQuestion = new VOQuestion();
        voQuestion.QuestionIsFather = 0;
        voQuestion.FKQuestionCourseID = int.Parse(ddlCourseList.SelectedValue);
        voQuestion.QuestionCreateID = int.Parse(ViewState["UserID"].ToString());
        voQuestion.QuestionCreateTime = DateTime.Now;

        voQuestion.QuestionAnswer = "";            //
        voQuestion.QuestionDefaultScore = int.Parse(txtDefaultScore.Text);
        voQuestion.QuestionDiffculty = int.Parse(ddlDiffculty.SelectedValue);
        voQuestion.QuestionKen = txtKen.Text;


        int quesiontClass = 1;                 

        voQuestion.QuestionClass = quesiontClass;
        voQuestion.QuestionContent = txtQuestionContent.Value;
        voQuestion.QuestionParse = txtQuestionParse.Text;
        voQuestion.FKQuestionTypeID = int.Parse(ViewState["TypeID"].ToString());
        voQuestion.QuestionState = int.Parse(ddlQuestionState.SelectedValue);         //禁用1,启用2

        try
        {
            objQuestion.CreateQuestionOptionList(voQuestion, null);
            Script.ShowAndRedirect(this, GetLanageValueByKey("Msg_ManagerQuestion_WorkOK", PowerCreator.LMS.Language.LanagetItemType.Page), "ManagerQuestionInfo.aspx");
        }
        catch
        {
            Script.ShowAndRedirect(this, GetLanageValueByKey("Msg_ManagerQuestion_WorkNo", PowerCreator.LMS.Language.LanagetItemType.Page), "ManagerQuestionInfo.aspx");
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Script.RedirectURL("ManagerQuestionInfo.aspx");
    }

    protected void rdbtn_QuestionType_SelectedIndexChanged(object sender, EventArgs e)
    {
        string url = string.Empty;
        switch (rdbtn_QuestionType.SelectedValue)
        {
            case "1":
                url = "AddQuestionInfo_panduan.aspx";
                break;
            case "2":
                url = "AddQuestionInfo_danx.aspx";
                break;
            case "3":
                url = "AddQuestionInfo_duox.aspx";
                break;
            case "4":
                url = "AddQuestionInfo_tiank.aspx";
                break;
            case "5":
                url = "AddQuestioninfo_mingci.aspx";
                break;
            case "6":
                url = "AddQuestionInfo_jianda.aspx";
                break;
            case "7":
                url = "AddQuestionInfo_zuhe.aspx";
                break;
        }
        Script.RedirectURL(url);
    }
}
